<?php
namespace juven\libs {
    \defined( '_JEXEC' ) or die( 'Restricted access' );
    
    class Config extends DynamicContainer{
        
        public function __construct(array $array=array()){ parent::__construct($array); }
        
        /** 
         * @param string $configuration_file_path 
         * @param string $entry_point
         */
        public function Init($configuration_file_path, $entry_point){
            $this->entryPoint = $entry_point;
            require_once $configuration_file_path;
        }
        
        public function __get($name) {
            if (juven::eventsManager()!==\NULL){
                $dtp = new \stdClass();
                $dtp->requested_ItemName = $name;
                $dtp->ItemToReturn = parent::__get($name);
                juven::eventsManager()->publish(self::EVENT_onBefore_ReturnRequestedConfigItem(), $dtp);
                return $dtp->ItemToReturn;
            } else { return parent::__get($name); }
        }
        
        public function __set($name, $value) {
            if (juven::eventsManager()!==\NULL){
                $dtp = new \stdClass();
                $dtp->ItemName  = $name;
                $dtp->ItemValue = $value;
                juven::eventsManager()->publish(self::EVENT_onBefore_SetConfigItem(), $dtp);
                    parent::__set($dtp->ItemName, $dtp->ItemValue);
                juven::eventsManager()->publish(self::EVENT_onAfter_SetConfigItem(), $dtp);
            } else { parent::__set($name, $value); }
        }
        
        public static function EVENT_onBefore_ReturnRequestedConfigItem(){ return __CLASS__."\\".__FUNCTION__; }
        public static function EVENT_onBefore_SetConfigItem(){ return __CLASS__."\\".__FUNCTION__; }
        public static function EVENT_onAfter_SetConfigItem(){  return __CLASS__."\\".__FUNCTION__; }
    }
}
?>
